//
//  TopicTableViewCellOne.m
//  A_Project_DLS151129_SQ
//
//  Created by 宋强 on 16/2/26.
//  Copyright © 2016年 www.lanou3g.com蓝鸥. All rights reserved.
//

#import "TopicTableViewCellOne.h"

@implementation TopicTableViewCellOne
- (void)dealloc
{
    [_titleLabel release];
    [_imgView release];
    [_contentLabel release];
    [_timeLabel release];
    [_commentView release];
    [_commentLabe release];
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.titleLabel = [[UILabel alloc] init];
        _titleLabel.numberOfLines = 0;
       // _titleLabel.backgroundColor = [UIColor redColor];
        _titleLabel.font = [UIFont boldSystemFontOfSize:17];
        [self.contentView addSubview: _titleLabel];
        [_titleLabel release];
        self.imgView = [[UIImageView alloc] init];
       // _imgView.backgroundColor = [UIColor blueColor];
        [self.contentView addSubview:_imgView];
        [_imgView release];
        self.contentLabel = [[UILabel alloc] init];
       // _contentLabel.backgroundColor = [UIColor blueColor];
        _contentLabel.numberOfLines = 3;
        [self.contentView addSubview:_contentLabel];
        [_contentLabel release];
        self.commentView = [[UIImageView alloc] init];
        _commentView.image = [UIImage imageNamed:@"xiaoxi"];
        //_commentView.backgroundColor = [UIColor blueColor];
        [self.contentView addSubview:_commentView];
        [_commentView release];
        self.commentLabe = [[UILabel alloc] init];
     //   _commentLabe.backgroundColor = [UIColor yellowColor];
        [self.contentView addSubview:_commentLabe];
        _commentLabe.font = [UIFont systemFontOfSize:15];
        [_commentLabe release];
        self.timeLabel = [[UILabel alloc] init];
        _timeLabel.font = [UIFont systemFontOfSize:15];
        //_timeLabel.backgroundColor = [UIColor yellowColor];
        [self.contentView addSubview:_timeLabel];
        [_timeLabel release];
    }
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat titleH = [[self class] heightWithText:_titleLabel.text];
    _titleLabel.frame = CGRectMake(10, 10, self.frame.size.width - 20, titleH);
    CGRect titleFrame = _titleLabel.frame;
    _imgView.frame = CGRectMake(titleFrame.origin.x, titleFrame.origin.y + titleH + 10, 60, 60);
    CGRect imgFrame = _imgView.frame;
    //CGFloat h = [[self class] heightWithText:_contentLabel.text];
    _contentLabel.frame = CGRectMake(imgFrame.origin.x + imgFrame.size.width + 5, imgFrame.origin.y, self.frame.size.width - imgFrame.size.width - 10 - 5 - 10, 60);
    _timeLabel.frame = CGRectMake(_imgView.frame.origin.x, _imgView.frame.origin.y + _imgView.frame.size.height + 15, 100, 20);
    _commentLabe.frame = CGRectMake(self.frame.size.width - 20 - 40, _timeLabel.frame.origin.y, 40, 20);
    _commentView.frame = CGRectMake(_commentLabe.frame.origin.x - 5 - 40, _timeLabel.frame.origin.y, _commentLabe.frame.size.width - 5, _commentLabe.frame.size.height);

}
//自适应高度方法实现
+ (CGFloat)heightWithText:(NSString *)text
{
    NSDictionary *dic = @{NSFontAttributeName: [UIFont systemFontOfSize:17]};
    CGSize s = CGSizeMake(355, 1000);
    CGRect r = [text boundingRectWithSize:s options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return r.size.height;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
